<?php
    namespace app\api\controller;
    use think\Controller;

    class Base extends Controller
    {
        public $account;
        protected $data;
        public function _initialize(){
            header("Access-Control-Allow-Origin:http://127.0.0.1:8080");
            header('Access-Control-Allow-Credentials:true');
            header('Access-Control-Allow-Methods:GET, POST, OPTIONS');

            $isLogin = $this->isLogin();
            if(!$isLogin){
                $data['is_login']=0;
                json(1,'身份验证已过期',$data);
            }else{
                $data['is_login']=1;
            }

            $this->data = $data;
        }

        public function isLogin(){
            $user = $this->getLoginUser();
            if($user && $user['id']){
                return true;
            }
            return false;
        }

        public function getLoginUser(){
            if(!$this->account){
                $this->account = session('user','','user');
            }
            return $this->account;
        }
    }